package remote{

	
	import entidades.Status;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class StatusRemote {
		
		public function exibirStatus( result:Function, tipo:Number ):void{
			var async:AsyncToken = _remote.listStatus(tipo);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function exibirCondicaoPagamento( result:Function ):void{
			var async:AsyncToken = _remote.listCondicaoPagamento();
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}	
		
		public function buscarStatus(result:Function, numStatus:Number, Status:Number,
										 idStatus:Number, dtPlanejada:Date, dtCriacaoIni:Date, dtCriacaoFim:Date):void{
			var result:Function;
			var async:AsyncToken = _remote.buscarStatus(numStatus, Status,
				idStatus, dtPlanejada, dtCriacaoIni, dtCriacaoFim);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function gravarStatus(status:Status ):void{
			var result:Function;
			var async:AsyncToken = _remote.addStatus(status);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		//--------------------setup----------------------------//
		private var _remote:RemoteObject;
		
		public function StatusRemote(){
			_remote = new RemoteObject();
			_remote.showBusyCursor = true;
			_remote.destination = 'StatusService';
		}
		
		private function defaultFaultHandler(e:FaultEvent):void{
			Alert.show( "Estamos com problemas no servidor! Tente novamente mais tarde!","Status");
		}
		
		private static var _instance:StatusRemote;
		public static function getInstance():StatusRemote{
			if(_instance == null){
				_instance = new StatusRemote();
			}
			return _instance;
		}
	}
}